home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
data
/
ysuty2
/
filetest.c
< prev
next >
Wrap
Text File
|
1993-07-08
|
2KB
|
76 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
void main(int argc,char *argv[])
{
int i,n;
char *atr[]={"","<DIR>"},*fn[64],sd[64],buf[64*14];
if(argc<2)n=YSC_getDosFiles(fn,sd,64,"","",buf);
else n=YSC_getDosFiles(fn,sd,64,"",argv[1],buf);
for(i=0; i<n; i++)
{
printf("%s %s\n",fn[i],atr[sd[i]]);
}
}
int YSC_getDosFiles(char *fn[],char *sd,int max,char *path,char *wc,char *buf)
{
struct find_t dir;
int pl,i,n;
int rst;
char Path[128],tmn;
if(*wc==0)wc="*.*";
pl=strlen(path);
tmn=path[pl-1];
if (pl==0) strcpy(Path,"*.*");
else if(tmn!='\\' && tmn!=':')sprintf(Path,"%s\\%s",path,"*.*");
else sprintf(Path,"%s%s",path,"*.*");
n=0;
for(i=0; n<max ; i++)
{
if(i==0)rst=_dos_findfirst(Path,_A_SUBDIR,&dir);
else rst=_dos_findnext(&dir);
if(rst)break;
if( dir.attrib & _A_SUBDIR )
{
strcpy(buf,dir.name);
fn[n]=buf;
sd[n]=1;
buf += strlen(dir.name)+1;
n++;
}
}
if (pl==0) strcpy(Path,wc);
else if(tmn!='\\' && tmn!=':')sprintf(Path,"%s\\%s",path,wc);
else sprintf(Path,"%s%s",path,wc);
for(i=0; n<max ; i++)
{
if(i==0)rst=_dos_findfirst(Path,_A_NORMAL,&dir);
else rst=_dos_findnext(&dir);
if(rst)break;
if((dir.attrib & _A_SUBDIR)==0)
{
strcpy(buf,dir.name);
fn[n]=buf;
sd[n]=0;
buf += strlen(dir.name)+1;
n++;
}
}
return n;
}